using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using ISolutions.WCMTools.Impl;

namespace ISolutions.WCMTools.FeatureReceiver
{
    class ApprovalConfigCopyReceiver : SPFeatureReceiver
    {
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWeb web = properties.Feature.Parent as SPWeb;
            if (web != null && !web.IsRootWeb)
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite elevatedSite = new SPSite(web.Site.ID))
                    {
                        using (SPWeb elevatedWeb = elevatedSite.OpenWeb(web.ID))
                        {
                            ApprovalWorkflowHelper.ApplyApprovalWorkflowConfig(elevatedWeb.ParentWeb, elevatedWeb);
                        }
                    }
                });
            }
        }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
        }

        public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        {
        }

        public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        {
        }
    }
}
